package com.example.musicwebcon.controller;

import com.example.musicwebcon.model.ResponseMessage;
import com.example.musicwebcon.model.dto.songListDTO;
import com.example.musicwebcon.model.songList;
import com.example.musicwebcon.service.serviceInterface.IsongListService;
import org.apache.catalina.connector.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/songlist")
public class songListController {
    @Autowired
    IsongListService songListService;
    @PostMapping
    public ResponseMessage add(@Validated @RequestBody songListDTO songlist){
        songList songList = songListService.add(songlist);
        return ResponseMessage.success(songList);
    }
    @GetMapping("/{songlistId}")
    public ResponseMessage getbySonglistId(@PathVariable String songlistId){
        songList songList = songListService.getsonglistId(songlistId);
        return ResponseMessage.success(songList);
    }
    @GetMapping("/all/{userId}")
    public ResponseMessage getbyUserId(@PathVariable String userId){
        Iterable<songList> songLists = songListService.getAllByUserId(userId);
        return ResponseMessage.success(songLists);
    }

    @PutMapping("/{id}")
    public ResponseMessage edit(@PathVariable String id,
                                @RequestParam(value = "songListName", required = false) String songListName,
                                @RequestParam(value = "description", required = false) String description,
                                @RequestParam(value = "file", required = false) MultipartFile file) {
        // 调用服务层方法进行更新
        songList updatedSongList = songListService.edit(id, songListName, description, file);
        return ResponseMessage.success(updatedSongList);
    }

    @DeleteMapping("/{songlistId}")
    public ResponseMessage deleteBysonglistId(@PathVariable String songlistId){
        songListService.deleteBysonglistId(songlistId);
        return ResponseMessage.success(null);
    }
}
